package com.kyang.musiconline.model;

import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * @author kyang
 */
@Data
public class Vinyl implements Serializable, RowMapper<Vinyl> {
    @Serial
    private static final long serialVersionUID = -5888122007431525177L;

    private String id;
    private String musicUser;
    private String musicName;
    private String musicAuthor;
    private String musicIntro;
    private String issuingDate;
    private BigDecimal musicPrice;
    private String musicCover;
    private Date createDate;
    private Date updateDate;
    private Integer isDelete = 0;

    public Object[] convertObjects() {
        Object[] objects = new Object[11];
        objects[0] = this.id;
        objects[1] = this.musicUser;
        objects[2] = this.musicName;
        objects[3] = this.musicAuthor;
        objects[4] = this.musicIntro;
        objects[5] = this.issuingDate;
        objects[6] = this.musicPrice;
        objects[7] = this.musicCover;
        objects[8] = this.createDate;
        objects[9] = this.updateDate;
        objects[10] = this.isDelete;
        return objects;
    }

    @Override
    public Vinyl mapRow(ResultSet rs, int rowNum) throws SQLException {
        Vinyl vinyl = new Vinyl();
        vinyl.setId(rs.getString("id"));
        vinyl.setMusicUser(rs.getString("music_user"));
        vinyl.setMusicName(rs.getString("music_name"));
        vinyl.setMusicAuthor(rs.getString("music_author"));
        vinyl.setMusicIntro(rs.getString("music_intro"));
        vinyl.setIssuingDate(rs.getString("issuing_date"));
        vinyl.setMusicPrice(rs.getBigDecimal("music_price"));
        vinyl.setMusicCover(rs.getString("music_cover"));
        vinyl.setCreateDate(rs.getDate("create_date"));
        vinyl.setUpdateDate(rs.getDate("update_date"));
        vinyl.setIsDelete(rs.getInt("is_delete"));
        return vinyl;
    }
}
